package csdn;

import java.io.FileInputStream;
import java.io.IOException;

public class Test4 {
    public static void main(String[] args) {
        String pathname="D:\\javacode\\javacode\\IO_1\\test_1.txt";//文件路径
        byte[] buf = new byte[8]; //一次读取 8 个字节
        int readlen=0;
        FileInputStream fileInputStream=null;

        try {
            //创建FileInputStream对象，用于读取文件
            fileInputStream = new FileInputStream(pathname);
            while((readlen=fileInputStream.read(buf))!=-1){
                System.out.print(new String(buf,0,readlen));//将读取的内容转为char显示
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {
            //关闭文件流，释放资源
            try {
                fileInputStream.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
